<template>
  <div id="app">
    <div id="nav">
      <!-- 编程式导航 -->
      <a @click="jumphome">Home</a> |

      <!-- <router-link to="/">Home</router-link> | -->
      <router-link to="/about">About</router-link> |
      <router-link to="/news">News</router-link> |

      <!-- 声明式导航 -->
      <!-- 声明式导航传参 -->
      <!-- path query 类似get，在地址栏显示 刷新页面，数据不会丢失 -->
      <router-link :to="{path:'/product',query:{id:1}}">Product</router-link>
      <!-- name params 类似post,在地址栏不会显示 刷新页面，数据丢失 -->
      <!-- <router-link :to="{name:'Product',params:{id:1}}">Product</router-link> -->
    </div>
    <router-view/>
    <div class="left">
      <router-view name='a' />
    </div>
    <div class="right">
      <router-view name='b' />
    </div>
  </div>
</template>

<script>
export default {
  methods:{
    jumphome(){
      // this.$router.push('/');
      //传参
      this.$router.push({path:'/',query:{id:1}});
      // this.$router.push({name:'/',params:{id:1}});
      // this.$router.push({name:'/',query:{id:1}});  //不推荐这种写法
    }
  }
}
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  .left,.right{
    width:50%;
    float: left;
  }
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
